package com.ruoyi.wechat.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.wechat.domain.FacilityType;
import com.ruoyi.wechat.domain.WxCampFacilityVo;
import com.ruoyi.wechat.service.IWxFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wechat/facility")
/**
 * 微信小程序API 服务设施管理
 */
public class WxFacilityController extends BaseController {
    @Autowired
    private IWxFacilityService wxFacilityService;
    /**
     * 获取服务设施类型以及对应的服务设施数据列表
     */
    @GetMapping("/list")
    public AjaxResult list(){
        List<FacilityType> list =wxFacilityService.facilityTypeList();
        return success(list);
    }
    /**
     * 根据营地Id和服务设施Id集合完成批量添加
     */
    @PostMapping("/wxadd")
    public AjaxResult add(@RequestBody WxCampFacilityVo wxCampFacilityVo){
        if(wxCampFacilityVo.getCampId()==null){
            return error("营地Id不能为空");
        }
        if(wxCampFacilityVo.getFacilityIds()==null){
            return error("服务设施Id不能为空");
        }
        return toAjax(wxFacilityService.insertCampFacility(wxCampFacilityVo.getCampId(),wxCampFacilityVo.getFacilityIds()));
    }
    /**
     * 根据营地Id查询该营地的服务设施列表
     */
    @GetMapping("/wxgetInfo/{campId}")
    public AjaxResult getInfo(@PathVariable("campId") String campId){
        if(campId==null){
            return error("该营地不能为空");
        }
        List<FacilityType> list=wxFacilityService.campFacilityListByCampId(campId);
        return success(list);
    }
    /**
     * 根据营地Id完成删除
     */
    @DeleteMapping("/wxdelete/{campId}")
    public AjaxResult delete(@PathVariable("campId") String campId){
        if(campId==null){
            return error("营地id不为空");
        }
        return toAjax(wxFacilityService.deleteCampFacilityByCampId(campId));
    }




}
